// 大规模剧情扩展系统 - 100+种剧情分支
class MegaStoryExpansion {
    constructor() {
        this.stories = {};
        this.choiceConsequences = {};
        this.dynamicContent = {};
        this.init();
    }

    init() {
        this.setupMegaStoryData();
        this.setupChoiceConsequences();
        this.setupDynamicContent();
        console.log('🎭 大规模剧情系统已加载 - 100+种剧情分支');
    }

    setupMegaStoryData() {
        // 第一章扩展 - 30种分支
        this.stories.chapter1 = {
            // 实验室发现分支 - 数据分析路线
            scene1_1a: { // 立即检查数据
                title: "数据异常",
                content: "你立即查看设备的数据读数，屏幕上的数字让你震惊。量子波动频率完全超出了理论范围，这种现象在科学文献中从未记录过。",
                image: "images/data_anomaly.svg",
                choices: [
                    { id: "analyze_data", text: "深入分析数据模式", leads_to: "chapter1_scene1_1a1", stats: { science: 1 } },
                    { id: "record_everything", text: "记录所有读数", leads_to: "chapter1_scene1_1a2", stats: { caution: 1 } },
                    { id: "cross_reference", text: "与理论模型对比", leads_to: "chapter1_scene1_1a3", stats: { knowledge: 1 } },
                    { id: "call_colleague", text: "联系其他研究员", leads_to: "chapter1_scene1_1a4", stats: { cooperation: 1 } }
                ]
            },
            scene1_1a1: {
                title: "模式识别",
                content: "通过深入分析，你发现数据中隐藏着某种模式。这些波动似乎不是随机的，而是遵循着一种未知的数学序列。你的心跳加速，意识到这可能是重大发现。",
                choices: [
                    { id: "decode_pattern", text: "尝试解码模式", leads_to: "chapter1_scene1_1a1a", stats: { analysis: 2 } },
                    { id: "mathematical_analysis", text: "进行数学分析", leads_to: "chapter1_scene1_1a1b", stats: { math: 1 } },
                    { id: "quantum_interpretation", text: "从量子角度解释", leads_to: "chapter1_scene1_1a1c", stats: { physics: 1 } },
                    { id: "seek_pattern_origin", text: "寻找模式起源", leads_to: "chapter1_scene1_1a1d", stats: { investigation: 1 } }
                ]
            },
            scene1_1a1a: {
                title: "密码破译",
                content: "你开始尝试解码这个神秘的模式。经过几个小时的努力，你发现这个模式实际上是一种未知的通信协议。有什么东西在试图通过量子设备与你交流。",
                choices: [
                    { id: "establish_communication", text: "尝试建立通信", leads_to: "chapter1_scene1_1a1a1", stats: { communication: 2, courage: 1 } },
                    { id: "decode_message", text: "解码完整信息", leads_to: "chapter1_scene1_1a1a2", stats: { decryption: 2 } },
                    { id: "trace_source", text: "追踪信号源头", leads_to: "chapter1_scene1_1a1a3", stats: { tracking: 1 } },
                    { id: "alert_authorities", text: "通知相关部门", leads_to: "chapter1_scene1_1a1a4", stats: { responsibility: 1 } }
                ]
            },
            scene1_1a1a1: {
                title: "第一次接触",
                content: "你成功建立了通信连接。一个来自另一个维度的声音清晰地传达到你的意识中：'我们一直在等待有人能够理解我们的信号。你的世界面临着巨大的危险，只有通过合作才能避免灾难。'",
                choices: [
                    { id: "accept_cooperation", text: "接受合作提议", leads_to: "chapter2_cooperation_path", stats: { trust: 2, openness: 1 } },
                    { id: "demand_proof", text: "要求提供证据", leads_to: "chapter2_skeptical_path", stats: { skepticism: 2 } },
                    { id: "ask_about_danger", text: "询问具体危险", leads_to: "chapter2_investigation_path", stats: { caution: 1, knowledge: 1 } },
                    { id: "negotiate_terms", text: "协商合作条件", leads_to: "chapter2_diplomatic_path", stats: { diplomacy: 2 } }
                ]
            },
            
            // 小心接近分支 - 直接接触路线
            scene1_2a: { // 小心接近发光设备
                title: "蓝光之谜",
                content: "你小心翼翼地接近发光的设备。蓝光变得更加强烈，你感觉到一种奇特的能量在空气中涌动。突然，你听到了一个微弱的声音...",
                choices: [
                    { id: "listen_carefully", text: "仔细聆听声音", leads_to: "chapter1_scene1_2a1", stats: { perception: 1 } },
                    { id: "touch_device", text: "触摸发光设备", leads_to: "chapter1_scene1_2a2", stats: { courage: 2 } },
                    { id: "step_back", text: "谨慎后退", leads_to: "chapter1_scene1_2a3", stats: { caution: 2 } },
                    { id: "use_equipment", text: "使用检测设备", leads_to: "chapter1_scene1_2a4", stats: { methodology: 1 } }
                ]
            },
            scene1_2a2: {
                title: "能量融合",
                content: "当你的手接触到设备表面时，一股强大的能量瞬间流遍你的全身。你感觉自己的意识正在扩展，能够感知到平时无法察觉的维度。你看到了时间的分支，看到了无数可能性的重叠。",
                choices: [
                    { id: "embrace_power", text: "拥抱这种力量", leads_to: "chapter2_power_path", stats: { power: 3, transformation: 1 } },
                    { id: "fight_influence", text: "抵抗这种影响", leads_to: "chapter2_resistance_path", stats: { willpower: 2, independence: 1 } },
                    { id: "study_sensation", text: "研究这种感觉", leads_to: "chapter2_research_path", stats: { analysis: 1, science: 1 } },
                    { id: "seek_control", text: "尝试控制力量", leads_to: "chapter2_control_path", stats: { control: 2 } }
                ]
            },
            
            // 紧急撤离分支 - 安全第一路线
            scene1_3a: { // 立即关闭设备并撤离
                title: "安全第一",
                content: "你迅速关闭所有设备并触发紧急协议。虽然错过了深入研究的机会，但你的谨慎可能避免了潜在的危险。警报声在实验室中回响，安全团队很快赶到现场。",
                choices: [
                    { id: "call_security", text: "联系安全部门", leads_to: "chapter1_scene1_3a1", stats: { security: 1 } },
                    { id: "document_incident", text: "记录事件详情", leads_to: "chapter1_scene1_3a2", stats: { documentation: 1 } },
                    { id: "monitor_remotely", text: "远程监控", leads_to: "chapter1_scene1_3a3", stats: { monitoring: 1 } },
                    { id: "investigate_cause", text: "调查异常原因", leads_to: "chapter1_scene1_3a4", stats: { investigation: 1 } }
                ]
            },
            scene1_3a1: {
                title: "安全评估",
                content: "安全部门的专家们对设备进行了全面检查。他们发现设备内部的量子场发生了前所未有的变化，这种变化可能对整个设施造成影响。部门主管决定将此事上报给更高层。",
                choices: [
                    { id: "volunteer_expertise", text: "提供专业协助", leads_to: "chapter2_expert_path", stats: { expertise: 2, cooperation: 1 } },
                    { id: "request_investigation", text: "要求深入调查", leads_to: "chapter2_official_path", stats: { procedure: 1 } },
                    { id: "express_concerns", text: "表达安全担忧", leads_to: "chapter2_safety_path", stats: { safety: 2 } },
                    { id: "suggest_containment", text: "建议隔离措施", leads_to: "chapter2_containment_path", stats: { containment: 2 } }
                ]
            }
        };

        // 第二章 - 多维度探索 (40种分支)
        this.stories.chapter2 = {
            // 合作路线
            cooperation_path: {
                title: "跨维度合作",
                content: "你决定与来自平行维度的存在合作。他们向你揭示了一个惊人的事实：您的世界正在经历一场时空崩地，而只有通过多个维度的协作才能避免灾难。",
                choices: [
                    { id: "learn_technology", text: "学习他们的技术", leads_to: "chapter2_tech_path", stats: { technology: 2, learning: 1 } },
                    { id: "share_knowledge", text: "分享你的知识", leads_to: "chapter2_exchange_path", stats: { sharing: 2, trust: 1 } },
                    { id: "plan_intervention", text: "制定干预计划", leads_to: "chapter2_planning_path", stats: { strategy: 2 } },
                    { id: "establish_portal", text: "建立稳定通道", leads_to: "chapter2_portal_path", stats: { engineering: 2 } }
                ]
            },
            
            // 怀疑路线
            skeptical_path: {
                title: "谨慎的怀疑",
                content: "你要求提供更多证据来证明他们的说法。在你的坚持下，他们向你展示了一系列量子方程和数学模型，证明了他们所说的危险确实存在。",
                choices: [
                    { id: "verify_equations", text: "验证数学方程", leads_to: "chapter2_math_path", stats: { verification: 2, math: 1 } },
                    { id: "independent_research", text: "进行独立研究", leads_to: "chapter2_research_path", stats: { independence: 2, research: 1 } },
                    { id: "seek_peer_review", text: "寻求同行评议", leads_to: "chapter2_peer_path", stats: { collaboration: 1, academic: 1 } },
                    { id: "test_predictions", text: "测试他们的预测", leads_to: "chapter2_testing_path", stats: { testing: 2 } }
                ]
            },
            
            // 力量路线
            power_path: {
                title: "力量的觉醒",
                content: "你拥抱了这种神秘的力量，发现自己能够感知并影响多个维度的现实。你看到了无数个版本的你自己，每一个都在做着不同的决定。现在，你必须决定如何使用这种力量。",
                choices: [
                    { id: "explore_multiverse", text: "探索多元宇宙", leads_to: "chapter3_multiverse_path", stats: { exploration: 3, multiverse: 2 } },
                    { id: "help_all_versions", text: "帮助所有版本的自己", leads_to: "chapter3_helper_path", stats: { altruism: 3, connection: 1 } },
                    { id: "become_observer", text: "成为观察者", leads_to: "chapter3_observer_path", stats: { wisdom: 2, detachment: 1 } },
                    { id: "merge_realities", text: "尝试融合现实", leads_to: "chapter3_merger_path", stats: { ambition: 3, unity: 1 } }
                ]
            },
            
            // 专家路线
            expert_path: {
                title: "专家咨询",
                content: "你的专业知识得到了认可，你被邀请加入一个秘密研究项目。这个项目的目标是研究量子维度之间的相互作用。你发现这里聚集了世界上最优秀的科学家。",
                choices: [
                    { id: "lead_research", text: "主导研究方向", leads_to: "chapter3_leadership_path", stats: { leadership: 3, research: 2 } },
                    { id: "collaborate_equally", text: "平等合作", leads_to: "chapter3_team_path", stats: { teamwork: 2, collaboration: 2 } },
                    { id: "focus_on_theory", text: "专注理论研究", leads_to: "chapter3_theory_path", stats: { theory: 3, depth: 1 } },
                    { id: "pursue_applications", text: "追求实用应用", leads_to: "chapter3_application_path", stats: { practical: 3, innovation: 1 } }
                ]
            }
        };

        // 第三章 - 无限可能性 (30种分支)
        this.stories.chapter3 = {
            multiverse_path: {
                title: "多元宇宙探索者",
                content: "你成为了多元宇宙的探索者，在无数个平行世界之间穿行。每个世界都有其独特的物理定律和发展轨迹。你发现有些世界已经实现了时间旅行，有些则发展出了完全不同的技术。",
                choices: [
                    { id: "study_variations", text: "研究世界变化规律", leads_to: "chapter3_variation_path", stats: { analysis: 2, multiverse: 1 } },
                    { id: "collect_technologies", text: "收集各世界技术", leads_to: "chapter3_collector_path", stats: { technology: 3, curiosity: 1 } },
                    { id: "map_multiverse", text: "绘制多元宇宙地图", leads_to: "chapter3_mapper_path", stats: { mapping: 2, exploration: 2 } },
                    { id: "find_origin_point", text: "寻找原点世界", leads_to: "chapter3_origin_path", stats: { investigation: 3 } }
                ]
            },
            
            helper_path: {
                title: "跨维度守护者",
                content: "你决定帮助所有版本的自己解决他们各自面临的问题。在一些世界中，你需要阻止灾难性的实验；在另一些世界中，你需要帮助突破科技瓶颈。你成为了连接所有可能性的桥梁。",
                choices: [
                    { id: "create_network", text: "建立跨维度网络", leads_to: "chapter3_network_path", stats: { networking: 3, connection: 2 } },
                    { id: "teach_others", text: "传授跨维知识", leads_to: "chapter3_teacher_path", stats: { teaching: 2, wisdom: 2 } },
                    { id: "establish_protocols", text: "建立干预协议", leads_to: "chapter3_protocol_path", stats: { organization: 2, system: 2 } },
                    { id: "become_mediator", text: "成为维度调停者", leads_to: "chapter3_mediator_path", stats: { diplomacy: 3, balance: 1 } }
                ]
            },
            
            theory_path: {
                title: "理论大师",
                content: "你专注于理论研究，开始构建一套完整的多元宇宙理论体系。你的理论不仅解释了平行世界的存在，还预测了更高维度的可能性。你的数学方程开始显示出一些惊人的结果。",
                choices: [
                    { id: "publish_theory", text: "发表理论成果", leads_to: "chapter4_publication_path", stats: { fame: 2, academic: 3 } },
                    { id: "test_predictions", text: "测试理论预测", leads_to: "chapter4_testing_path", stats: { validation: 3, experiment: 2 } },
                    { id: "explore_implications", text: "探索理论含义", leads_to: "chapter4_implications_path", stats: { philosophy: 2, depth: 2 } },
                    { id: "seek_higher_dimensions", text: "寻找更高维度", leads_to: "chapter4_ascension_path", stats: { transcendence: 3, discovery: 2 } }
                ]
            }
        };

        // 第四章 - 命运十字路口 (25种分支)
        this.stories.chapter4 = {
            publication_path: {
                title: "科学革命的引领者",
                content: "你的理论发表后引起了全世界的轰动。你被誉为新时代的爱因斯坦，但也面临着巨大的质疑和挑战。一些政府要求你停止研究，担心这会威胁到现有的世界秩序。",
                choices: [
                    { id: "defend_research", text: "坚决为研究辩护", leads_to: "chapter4_defender_path", stats: { conviction: 3, courage: 2 } },
                    { id: "go_underground", text: "转入地下研究", leads_to: "chapter4_underground_path", stats: { secrecy: 2, determination: 2 } },
                    { id: "seek_protection", text: "寻求国际保护", leads_to: "chapter4_diplomatic_path", stats: { diplomacy: 2, strategy: 2 } },
                    { id: "share_openly", text: "公开分享知识", leads_to: "chapter4_open_path", stats: { openness: 3, trust: 2 } }
                ]
            },
                    
            testing_path: {
                title: "实验的验证",
                content: "你决定通过实验来验证你的理论。在精心设计的实验中，你成功创造了一个可控的微型平行世界。这个发现证明了你的理论正确，但也带来了前所未有的责任。",
                choices: [
                    { id: "expand_experiment", text: "扩大实验规模", leads_to: "chapter4_expansion_path", stats: { ambition: 3, scale: 2 } },
                    { id: "study_mini_world", text: "研究微型世界", leads_to: "chapter4_micro_path", stats: { observation: 2, detail: 3 } },
                    { id: "create_life", text: "在微世界创造生命", leads_to: "chapter4_creator_path", stats: { creation: 3, responsibility: 2 } },
                    { id: "establish_contact", text: "与微世界建立联系", leads_to: "chapter4_contact_path", stats: { communication: 3, empathy: 1 } }
                ]
            },
                    
            ascension_path: {
                title: "维度提升",
                content: "你的研究已经超越了三维空间的限制，开始接触更高维度的存在。你发现自己的意识正在发生根本性的变化，能够理解和操控更复杂的空间结构。你正在成为一个超越三维的存在。",
                choices: [
                    { id: "embrace_transcendence", text: "拥抱超越存在", leads_to: "chapter5_transcendent_path", stats: { transcendence: 5, evolution: 3 } },
                    { id: "maintain_humanity", text: "保持人性联系", leads_to: "chapter5_human_path", stats: { humanity: 3, connection: 2 } },
                    { id: "become_bridge", text: "成为维度之桥", leads_to: "chapter5_bridge_path", stats: { mediation: 3, service: 2 } },
                    { id: "explore_infinity", text: "探索无限维度", leads_to: "chapter5_infinite_path", stats: { exploration: 4, courage: 3 } }
                ]
            }
        };

        // 第五章 - 时空回音的传承 (20种分支 + 10种结局)
        this.stories.chapter5 = {
            transcendent_path: {
                title: "超越者的道路",
                content: "你完全拥抱了超越存在的状态，成为了一个能够在多个维度中自由移动的存在。你的意识不再局限于单一的身体，而是散布在无数个现实中。你看到了时间的本质，理解了存在的意义。",
                choices: [
                    { id: "become_cosmic_entity", text: "成为宇宙实体", leads_to: "ending_cosmic_god", stats: { cosmic: 5 } },
                    { id: "guide_evolution", text: "引导宇宙进化", leads_to: "ending_evolution_guide", stats: { guidance: 4 } },
                    { id: "merge_with_multiverse", text: "与多元宇宙融合", leads_to: "ending_universal_consciousness", stats: { unity: 5 } },
                    { id: "create_new_reality", text: "创造全新现实", leads_to: "ending_reality_creator", stats: { creation: 5 } }
                ]
            },
            
            human_path: {
                title: "人性的坚持",
                content: "尽管拥有了超凡的能力，你仍然选择保持作为人类的本质。你用你的知识和能力来帮助人类解决现实世界的问题，成为了科学和人性之间的桥梁。你的选择将影响整个人类文明的未来。",
                choices: [
                    { id: "advance_humanity", text: "推动人类进步", leads_to: "ending_human_advancement", stats: { progress: 4 } },
                    { id: "protect_earth", text: "保护地球家园", leads_to: "ending_earth_guardian", stats: { protection: 4 } },
                    { id: "teach_wisdom", text: "传授智慧", leads_to: "ending_wisdom_teacher", stats: { wisdom: 4 } },
                    { id: "live_quietly", text: "平静生活", leads_to: "ending_quiet_life", stats: { peace: 3 } }
                ]
            },
            
            bridge_path: {
                title: "维度之桥",
                content: "你选择成为连接不同维度和现实的永恒桥梁。你帮助不同世界的生命体相互交流和学习，促进多元宇宙的和谐与发展。你的存在成为了希望和合作的象征。",
                choices: [
                    { id: "establish_council", text: "建立跨维度议会", leads_to: "ending_dimensional_council", stats: { diplomacy: 5 } },
                    { id: "create_academy", text: "创建多元学院", leads_to: "ending_multiverse_academy", stats: { education: 4 } },
                    { id: "become_eternal_guardian", text: "成为永恒守护者", leads_to: "ending_eternal_guardian", stats: { dedication: 5 } }
                ]
            },
            
            infinite_path: {
                title: "无限探索",
                content: "你选择继续探索无限的可能性，永远不停止对未知的追求。你成为了永恒的旅行者，在无数的现实和维度中寻找新的奇迹和秘密。你的传奇将永远传颂下去。",
                choices: [
                    { id: "explore_beyond", text: "探索现实之外", leads_to: "ending_reality_explorer", stats: { adventure: 5 } },
                    { id: "seek_origin", text: "寻找宇宙起源", leads_to: "ending_origin_seeker", stats: { mystery: 5 } },
                    { id: "become_legend", text: "成为传奇", leads_to: "ending_eternal_legend", stats: { legend: 5 } }
                ]
            }
        };
    }

    setupChoiceConsequences() {
        // 选择后果系统 - 每个选择都会影响后续剧情
        this.choiceConsequences = {
            // 科学分析选择的后果
            analyze_data: {
                statsModifier: { science: 2, curiosity: 1 },
                unlockScenes: ["science_path_1", "analysis_branch"],
                characterReaction: "你的同事对你的分析能力印象深刻",
                futureOptions: ["advanced_theory", "peer_review"]
            },
            
            // 谨慎选择的后果
            step_back: {
                statsModifier: { caution: 2, survival: 1 },
                unlockScenes: ["safe_path_1", "cautious_branch"],
                characterReaction: "安全部门赞扬了你的谨慎态度",
                futureOptions: ["safety_protocol", "risk_assessment"]
            },
            
            // 勇敢探索的后果
            touch_device: {
                statsModifier: { courage: 2, exploration: 1 },
                unlockScenes: ["brave_path_1", "explorer_branch"],
                characterReaction: "你的勇气为科学发现开辟了新道路",
                futureOptions: ["direct_contact", "energy_manipulation"]
            }
        };
    }

    setupDynamicContent() {
        // 动态内容系统 - 根据玩家选择历史生成内容
        this.dynamicContent = {
            scientistPath: {
                condition: (choices) => choices.filter(c => c.includes('analyze') || c.includes('data')).length >= 3,
                contentModifier: "科学家路线：你以严谨的科学方法著称",
                specialScenes: ["scientist_recognition", "research_grant", "Nobel_consideration"]
            },
            
            explorerPath: {
                condition: (choices) => choices.filter(c => c.includes('explore') || c.includes('brave')).length >= 3,
                contentModifier: "探索者路线：你的勇气和好奇心推动着发现",
                specialScenes: ["explorer_reputation", "dangerous_discovery", "frontier_pioneer"]
            },
            
            guardianPath: {
                condition: (choices) => choices.filter(c => c.includes('safe') || c.includes('protect')).length >= 3,
                contentModifier: "守护者路线：你优先考虑安全和保护",
                specialScenes: ["guardian_title", "safety_innovation", "world_protector"]
            }
        };
    }

    // 获取动态调整的故事内容
    getDynamicStory(sceneId, playerChoices = []) {
        let baseStory = this.getStoryByPath(sceneId);
        if (!baseStory) return null;

        // 根据玩家选择历史调整内容
        const activePath = this.getActivePath(playerChoices);
        if (activePath) {
            baseStory = this.modifyStoryForPath(baseStory, activePath);
        }

        // 添加选择后果
        baseStory = this.addChoiceConsequences(baseStory, playerChoices);

        return baseStory;
    }

    getStoryByPath(sceneId) {
        // 解析场景路径
        const parts = sceneId.split('_');
        const chapter = parts[0];
        const sceneKey = sceneId;

        return this.stories[chapter] && this.stories[chapter][sceneKey] 
            ? JSON.parse(JSON.stringify(this.stories[chapter][sceneKey]))
            : null;
    }

    getActivePath(choices) {
        for (const [pathName, pathData] of Object.entries(this.dynamicContent)) {
            if (pathData.condition(choices)) {
                return pathData;
            }
        }
        return null;
    }

    modifyStoryForPath(story, pathData) {
        // 根据路径修改故事内容
        story.content = pathData.contentModifier + "\n\n" + story.content;
        
        // 添加特殊选择
        if (pathData.specialScenes) {
            story.choices.push({
                id: "special_path_choice",
                text: `${pathData.contentModifier}的特殊选择`,
                leads_to: pathData.specialScenes[0]
            });
        }

        return story;
    }

    addChoiceConsequences(story, choices) {
        // 为故事添加选择后果
        const lastChoice = choices[choices.length - 1];
        const consequence = this.choiceConsequences[lastChoice];
        
        if (consequence && consequence.characterReaction) {
            story.content += `\n\n${consequence.characterReaction}`;
        }

        return story;
    }

    // 生成基于选择的分支故事
    generateBranchStory(baseSceneId, choiceId, playerStats = {}) {
        const templates = [
            {
                condition: () => playerStats.science > 5,
                title: "科学发现",
                content: "你的科学知识让你能够理解这个现象的深层含义...",
            },
            {
                condition: () => playerStats.courage > 5,
                title: "勇敢面对",
                content: "你的勇气让你能够面对未知的挑战...",
            },
            {
                condition: () => playerStats.caution > 5,
                title: "谨慎行事",
                content: "你的谨慎态度帮助你避免了潜在的危险...",
            }
        ];

        const template = templates.find(t => t.condition()) || templates[0];
        
        return {
            title: template.title,
            content: template.content,
            choices: this.generateDynamicChoices(choiceId, playerStats)
        };
    }

    generateDynamicChoices(choiceId, playerStats) {
        const baseChoices = [
            { id: "continue_investigation", text: "继续调查", leads_to: "next_scene" },
            { id: "seek_help", text: "寻求帮助", leads_to: "help_scene" },
            { id: "take_break", text: "暂时休息", leads_to: "rest_scene" }
        ];

        // 根据玩家属性添加特殊选择
        if (playerStats.science > 3) {
            baseChoices.push({
                id: "scientific_analysis", 
                text: "进行科学分析", 
                leads_to: "science_scene"
            });
        }

        if (playerStats.courage > 3) {
            baseChoices.push({
                id: "bold_action", 
                text: "采取大胆行动", 
                leads_to: "action_scene"
            });
        }

        return baseChoices;
    }

    // 获取故事统计信息
    getStoryStats() {
        let totalScenes = 0;
        let totalChoices = 0;

        for (const chapter of Object.values(this.stories)) {
            for (const scene of Object.values(chapter)) {
                totalScenes++;
                totalChoices += scene.choices ? scene.choices.length : 0;
            }
        }

        return {
            totalScenes,
            totalChoices,
            totalPaths: Object.keys(this.dynamicContent).length,
            totalConsequences: Object.keys(this.choiceConsequences).length
        };
    }
}

// 创建全局实例
window.megaStoryExpansion = new MegaStoryExpansion();

// 扩展原有的故事管理器
if (window.storyManager) {
    const originalLoadScene = window.storyManager.loadScene;
    window.storyManager.loadScene = function(chapter, scene) {
        const sceneId = `chapter${chapter}_scene${scene}`;
        const megaStory = window.megaStoryExpansion.getDynamicStory(sceneId, this.playerChoices || []);
        
        if (megaStory) {
            this.currentStory = megaStory;
            window.gameEngine.displayScene(megaStory);
        } else {
            // 回退到原始方法
            originalLoadScene.call(this, chapter, scene);
        }
    };
}

console.log('📚 大规模剧情扩展系统已加载');
console.log('📊 剧情统计:', window.megaStoryExpansion.getStoryStats());

if (typeof module !== 'undefined' && module.exports) {
    module.exports = MegaStoryExpansion;
}